<script setup lang="ts">
import { ref } from "vue";
import { loginAPI } from "@/apis/login";

const form = ref({
  username: "",
  password: "",
});

const handleLogin = async () => {
  const { data } = await loginAPI(form.value);
  if (data) {
    localStorage.setItem("token", data.token);
    // 跳转到对应页面
    const url: string = location.protocol + "//" + location.hostname + ":2802";
    location.href = url;
  }
};
</script>

<template>
  <el-container>
    <el-form :model="form" label-width="auto">
      <el-form-item label="账号">
        <el-input v-model="form.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<style scoped></style>
